package com.telit.common.util;

import com.aliyuncs.push.model.v20160801.PushMessageToAndroidResponse;
import com.aliyuncs.push.model.v20160801.PushResponse;
import com.telit.common.constant.MsgConstants;
import com.telit.common.pojo.AliPushMessagePojo;
import com.telit.common.service.AliPushMessageService;
import com.telit.common.service.ParamsCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * @Auther amy
 * @Describe 阿里云推送消息
 */
@Component
public class AliyunPushMessageUtils {

    private static ParamsCheckService paramsCheckService;

    private static AliPushMessageService aliPushMessageService;

    @Autowired
    public AliyunPushMessageUtils(ParamsCheckService paramsCheckService,AliPushMessageService aliPushMessageService){
        AliyunPushMessageUtils.paramsCheckService = paramsCheckService;
        AliyunPushMessageUtils.aliPushMessageService = aliPushMessageService;
    }

    /**
     * 给所有的安卓端群发消息
     * @param message 消息内容
     * @param pushType 消息类型 MESSAGE NOTICE
     * @return
     * @throws Exception
     */
    public static PushMessageToAndroidResponse pushSimpleMsgToAllAndroid(String message,String pushType) throws Exception {
        return aliPushMessageService.pushSimpleMessageToAndroid(message,pushType,MsgConstants.TARGET_ALL,MsgConstants.TARGET_ALL);
    }

    /**
     * 给单个安卓端用户发送消息
     * @param message 消息内容
     * @param pushType 消息类型 MESSAGE NOTICE
     * @param target 推送目标: DEVICE:按设备推送 ALIAS : 按别名推送 ACCOUNT:按帐号推送  TAG:按标签推送; ALL: 广播推送
     * @param id 用户的标识
     * @return
     * @throws Exception
     */
    public static PushMessageToAndroidResponse pushSimpleMessageToAndroid(String message,String pushType,String target,String id) throws Exception {
        return aliPushMessageService.pushSimpleMessageToAndroid(message,pushType,target,id);
    }

    /**
     * 高级发送，发送自定义，复杂的消息体
     * @param pojo
     * @return
     * @throws Exception
     */
    public static PushResponse customizeAdvancedPush(AliPushMessagePojo pojo) throws Exception {
        paramsCheckService.checkPushParam(pojo);
        return aliPushMessageService.customizeAdvancedPush(pojo);
    }
}
